import React from 'react';
import {create} from 'dva-core';
import {Provider, connect} from 'react-redux';
import ExpoLoadFix from '../components/ExpoLoadFix';
import GlobalToast from '../components/GlobalToast';
import {Actions} from 'react-native-router-flux';

export {connect};

export default function(options) {
    const app = create(options)
    // 如果注册过 model则不需再次注册
    if(!global.registered) {
    	options.models.forEach(model => app.model(model));
    	if(options.plugins) options.plugins.forEach(plugin => app.use(plugin));
    }
    global.registered = true // 注：golbal 为react native 全局变量   类似 window
    app.start();
    const store = app._store;
    app.start = container => () => {
    	return (
    		<Provider store={store}>
    			<ExpoLoadFix>
    				<GlobalToast>
	        			{container}
	        		</GlobalToast>
	            </ExpoLoadFix>
	        </Provider>
    	);
    }
    app.getStore = () => store;
    return app;
}